<script setup lang='ts'>
import { ArrowRight } from '@element-plus/icons-vue'
import { onMounted, ref } from 'vue';
import { getTitleMaterial,userLogin } from "../../api/api";
import { useRouter, useRoute } from 'vue-router';
import contentpc from "../../components/pc/contentpc.vue";
const router = useRouter()
const route = useRoute()
const data = ref()
const title = ref()
const frequency = ref()
const isLonig = ref()
const onBack = () => {
    router.back()
}
//获取搜索的素材
const getallData = async () => {
    const res = await getTitleMaterial({title:title.value})
    data.value = res.data.data
}
onMounted(()=>{
    title.value = route.query.type
    getallData()
    ifLogin()
})
//判断是否登录
const ifLogin = async () => {
    const res = await userLogin({ _id: localStorage.getItem('mail') as string })
    if (res.data.code === '404') {
        localStorage.setItem('token', '')
        localStorage.setItem('mail', '')
        isLonig.value = false
        return
    }
    isLonig.value = true
    frequency.value = res.data.data.frequency
}
</script>

<template>
    <div class="color">
        <div class="headerpc">
            <div class="title">
                <el-page-header title="返回" @back="onBack">
                    <template #content>
                        <div class="flex items-center">
                            <img src="../../assets/t.png" style="width: 20%;margin-left: -50px" alt="">
                            <el-tag class="tag" v-if="isLonig">积分：{{frequency}}</el-tag>
                            <el-tag class="tag" type="danger" v-if="!isLonig">未登录</el-tag>
                        </div>
                    </template>
                </el-page-header>
            </div>
        </div>
        <div class="h"></div>
        <div class="crumb">
            <el-breadcrumb :separator-icon="ArrowRight">
                <el-breadcrumb-item>首页</el-breadcrumb-item>
                <el-breadcrumb-item>{{title}}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <contentpc :data="data" :isTrue="true"></contentpc>
    </div>
</template>

<style scoped>
.color {
    background-color: #f5f2f0;
    min-height: 100vh !important;
}

.flex {
    display: flex;
    justify-content: center;
    align-items: center;
}

.text-large,
.mr-2,
.tag {
    position: relative;
    left: 5px;
}

.tag {
    left: 15px;
}

.headerpc {
    width: 100%;
    height: 60px;
    position: fixed;
    top: 0;
    background-color: rgba(255, 255, 255, 0.904);
    filter: blur(0.3px);
    z-index: 1;
}

.title {
    max-width: 1500px;
    height: 60px;
    box-sizing: border-box;
    margin: auto;
    padding: 10px;
}

.crumb {
    max-width: 1500px;
    margin: auto;
    margin-top: 60px;
}

.h {
    height: 20px
}

.data {
    max-width: 1500px;
    min-height: 600px;

    margin: auto;
    margin-top: 20px;
    display: grid;
    grid-template-columns: 73% 25%;
    gap: 2%;
}

.img {
    background-color: white;
    box-sizing: border-box;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.Ddata {
    background-color: white;
    box-sizing: border-box;
    padding: 20px;
}

.title {
    width: 100%;
    text-align: center;
}

.xq {
    width: 90%;
    min-height: 10px;
    margin: auto;
}

p {
    margin-top: 10px;
}

.text {
    width: 90%;
    color: white;
    min-height: 50px;
    margin: auto;
    margin-top: 30px;
    border-radius: 10px;
    background-color: #999;
    box-sizing: border-box;
    padding: 20px
}
.icon{
    width: 20px;
}
.btnData {
    width: 90%;
    height: 40px;
    margin: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
}
.btn {
    width: 62%;
    height: 40px;
    background-color: #67c23a;
    color: white;
    display: flex;
    border-radius: 5px;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: 0.8s background-color ease, 0.8s color ease;
}
.btn:active{
    box-shadow: 0 0 5px 5px #ccc;
}
.btn:hover {
    background-color: rgba(255, 0, 0, 0.815);
    color: whitesmoke;
}

span {
    color: black;
}

p {
    color: #999;
}
</style>